/*
 * Copyright 2010-2011 Marcin Blazejewski
 *
 * This file is part of Ground0.
 *
 * Ground0 is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Ground0 is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Ground0. If not, see <http://www.gnu.org/licenses/>.
 *
 */


#ifndef GARAGE_H_
#define GARAGE_H_

#include "eye.hpp"
#include "stuff.hpp"
#include "midlev.hpp"
#include "geometry.hpp"
#include "collision.hpp"

#include <map>
#include <vector>
#include <string>

using namespace std;

#define SLIDE_R       10

enum Mode { M_IDLE, M_SWITCH_NEXT, M_SWITCH_PREV };

class Garage : public BasicScene, public Controller {
private:
    GLUquadricObj         *q_sphere;
    Stuff                 *cme_model;
    list<CollisionNode*>::iterator cme_node;

    void                   draw_collision_model(CollisionModel &cm);
    void                   cme_next_node(int n=1);
    void                   cme_edit_node(Vector dcenter, float dsize);
    void                   cme_add_node();
    void                   cme_delete_node();
    void                   save_cm();

public:
    vector<string>         names;
    vector<Block*>         ships;
    vector<CollisionModel*>cms;
    int                    current;
    Quaternion             orientation;
    Vector                 pos;
    Vector                 cam_focus;
    bool                   rotate;
    bool                   show_cm;

    Garage();
    virtual ~Garage();

    virtual void           on_keydown(struct SDL_KeyboardEvent *ev);
    virtual void           on_keyup(struct SDL_KeyboardEvent *ev);
    virtual void           on_mouse_down(struct SDL_MouseButtonEvent *ev);
    virtual void           on_mouse_up(struct SDL_MouseButtonEvent *ev);
    virtual void           tick(unsigned int ms);
    virtual void           render();
    void                   draw_grid();

    void                   switch_ship(int d = 1);
    void                   add_ship_model(const char *name);
    Block*                 get_current_model();
    
};


#endif
